package com.eschool.beans;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import com.eschool.model.School;
import com.eschool.model.User;
import com.eschool.service.CustomerService;
import com.eschool.service.impl.CustomerServiceImpl;

@ManagedBean(name="customerBean")
@ViewScoped
public class CustomerBean {
	
	School school = new School();
	User user = new User();
	private boolean status = true;
	
	public boolean getStatus() {
		return status;
	}
	public void setStatus(boolean status) {
		this.status = status;
	}

	CustomerService customerService = new CustomerServiceImpl();
	
	public School getSchool() {
		return school;
	}
	public void setSchool(School school) {
		
		this.school = school;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	public String action()
	{
		String message = "";
		
		if(customerService.addCustomer(school)) {
			message = "School Successfully Added";
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Info Message", message));
		}
		
		else {
			message = "School Not Added";
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error Message", message));
		}
		
		//System.out.println(school.getExpiryDate());
		
		return "AddBranch";
	}
	
	public String updateStatus()
	{
		System.out.print("Status: " + status);
		return "";
	}
	
	private String password;
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String updatePassword()
	{
		return "";
	}

}
